<!DOCTYPE html>
<head>
  <title>Subresource loading with Web Bundles</title>
  <script type="webbundle">
    {
      "source":"../resources/wbn/hello.wbn",
      "resources": [
        "http://127.0.0.1:8000/loading/wbn/resources/wbn/server/hello/script.js",
        "http://127.0.0.1:8000/loading/wbn/resources/wbn/server/hello/notfound.js"
      ]
    }
  </script>
</head>
<body>
<script>
(async () => {
if (window.testRunner) {
  testRunner.dumpAsText();
  testRunner.waitUntilDone();
}

// Delay running the test until "didFinishLoadForFrame" is printed.
// This is intended to avoid the flakiness of the result outputs.
await new Promise((resolve) => {
    window.addEventListener('load', () => setTimeout(resolve, 0));
  });

if (!HTMLScriptElement.supports('webbundle')) {
  console.error("Subresource Web Bundles is not supported");
  testRunner.notifyDone();
  return;
}

await new Promise((resolve, reject) => {
    const script = document.createElement('script');
    script.src = 'http://127.0.0.1:8000/loading/wbn/resources/wbn/server/hello/script.js';
    script.onload = resolve;
    script.onerror = reject;
    document.body.appendChild(script);
  });

await new Promise((resolve, reject) => {
    // This request should fail rather than be loaded from the network.
    const script = document.createElement('script');
    script.src = 'http://127.0.0.1:8000/loading/wbn/resources/wbn/server/hello/notfound.js';
    script.onload = reject;
    script.onerror = () => {
	// Wait for the console message to be logged.
	setTimeout(resolve, 100);
    }
    document.body.appendChild(script);
  });

testRunner.notifyDone();
})();
</script>
</body>
